
#include<iostream>
#include<vector>
using namespace std;
#define INF 0x3f3f3f3f

int findmin(vector<int>& lowcost, vector<int>& S, int n)
{
    int min = INF, k = -1;
    for (int i = 0; i < n; i++)
    {
        if (S[i] == 0 && lowcost[i] < min)
        {
            min = lowcost[i];
            k = i;
        }
    }
    return k;
}

int Prim(vector<vector<int>>& G, int n, vector<int>& lowcost)
{
    vector<int> S;
    S.resize(n);
    int sum = 0;
    for(int i = 0; i< n; i++)
    {
        int k = findmin(lowcost, S, n);
        if (k == -1)
            return sum;
        S[k] = 1;
        sum += lowcost[k];
        for (int j = 0; j < n; j++)
        {
            if (S[j] == 0 && G[k][j] < lowcost[j])
                lowcost[j] = G[k][j];
        }
    }
    return sum;
}

int main()
{
    int n, e;
    cin >> n >> e;
    vector<vector<int>> G;
    vector<int> lowcost;
    G.resize(n);
    lowcost.resize(n);
    for (int i = 0; i < n; i++)
    {
        G[i].assign(n, INF);
        cin >> lowcost[i];
    }
    while (e--)
    {
        int i, j, f;
        cin >> i >> j >> f;
        G[i][j] = G[j][i] = f;
    }
    int sum = Prim(G, n, lowcost);
    cout << sum;
    return 0;
}